{php}
    // 获取一级联动数据
    $level_one  = get_level_data($form['table'], 0, $form['pid']);
    $level_key  = [];
    $level_data = [];

    // 有默认值
    if ($form['value'] != '') {
        $level_key_data = get_level_key_data($form['table'], $form['value'], $form['key'], $form['option'], $form['pid']);
        $level_key = $level_key_data['key'];
        $level_data = $level_key_data['data'];
        sort($level_key);
        $level_data = array_reverse($level_data);
    }
{/php}
<div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12" id="form_group_{$form.name}">
    <label class="col-xs-12 label-title">{$form.title|htmlspecialchars}</label>
    <div class="col-sm-3 select-box">
        <select class="js-select2 form-control select-linkages" id="linkages_{$form.name}_1" name="{$form.name}[1]" data-token="{$form.token}" data-pidkey="{$form.pid|default='pid'}" data-next-level="2" data-next-level-id="linkages_{$form.name}_2">
            <option value="">{:lang('请选择')}：</option>
            {volist name="level_one" id="option"}
            <option value="{$option[$form['key']]}" {if (isset($level_key[1]) && $level_key[1] == (string)$option[$form['key']])}selected{/if}>{$option[$form['option']]|raw|clear_js}</option>
            {/volist}
        </select>
    </div>

    {eq name="form.level" value="2"}
    <div class="col-sm-3 select-box">
        <select class="js-select2 form-control" name="{$form.name}[2]" id="linkages_{$form.name}_2">
            <option value="">{:lang('请选择')}：</option>
            {notempty name="level_data.1"}
                {volist name="level_data.1" id="option"}
                <option value="{$option[$form['key']]}" {if ($form.value == (string)$option[$form['key']])}selected{/if}>{$option[$form['option']]|raw|clear_js}</option>
                {/volist}
            {/notempty}
        </select>
    </div>
    {/eq}

    {eq name="form.level" value="3"}
    <div class="col-sm-3 select-box">
        <select class="js-select2 form-control select-linkages" id="linkages_{$form.name}_2" name="{$form.name}[2]" data-token="{$form.token}" data-pidkey="{$form.pid|default='pid'}" data-next-level="3" data-next-level-id="linkages_{$form.name}_3">
            <option value="">{:lang('请选择')}：</option>
            {notempty name="level_data.1"}
                {volist name="level_data.1" id="option"}
                <option value="{$option[$form['key']]}" {if (isset($level_key[2]) && $level_key[2] == (string)$option[$form['key']])}selected{/if}>{$option[$form['option']]|raw|clear_js}</option>
                {/volist}
            {/notempty}
        </select>
    </div>
    <div class="col-sm-3 select-box">
        <select class="js-select2 form-control" name="{$form.name}[3]" id="linkages_{$form.name}_3">
            <option value="">{:lang('请选择')}：</option>
            {notempty name="level_data.2"}
                {volist name="level_data.2" id="option"}
                <option value="{$option[$form['key']]}" {if ($form.value == (string)$option[$form['key']])}selected{/if}>{$option[$form['option']]|raw|clear_js}</option>
                {/volist}
            {/notempty}
        </select>
    </div>
    {/eq}

    {eq name="form.level" value="4"}
    <div class="col-sm-3 select-box">
        <select class="js-select2 form-control select-linkages" id="linkages_{$form.name}_2" name="{$form.name}[2]" data-token="{$form.token}" data-pidkey="{$form.pid|default='pid'}" data-next-level="3" data-next-level-id="linkages_{$form.name}_3">
            <option value="">{:lang('请选择')}：</option>
            {notempty name="level_data.1"}
                {volist name="level_data.1" id="option"}
                <option value="{$option[$form['key']]}" {if (isset($level_key[2]) && $level_key[2] == (string)$option[$form['key']])}selected{/if}>{$option[$form['option']]|raw|clear_js}</option>
                {/volist}
            {/notempty}
        </select>
    </div>
    <div class="col-sm-3 select-box">
        <select class="js-select2 form-control select-linkages" id="linkages_{$form.name}_3"  name="{$form.name}[3]" data-token="{$form.token}" data-pidkey="{$form.pid|default='pid'}" data-next-level="4" data-next-level-id="linkages_{$form.name}_4">
            <option value="">{:lang('请选择')}：</option>
            {notempty name="level_data.2"}
                {volist name="level_data.2" id="option"}
                <option value="{$option[$form['key']]}" {if (isset($level_key[3]) && $level_key[3] == (string)$option[$form['key']])}selected{/if}>{$option[$form['option']]|raw|clear_js}</option>
                {/volist}
            {/notempty}
        </select>
    </div>
    <div class="col-sm-3 select-box">
        <select class="js-select2 form-control" name="{$form.name}[4]" id="linkages_{$form.name}_4">
            <option value="">{:lang('请选择')}：</option>
            {notempty name="level_data.3"}
                {volist name="level_data.3" id="option"}
                <option value="{$option[$form['key']]}" {if ($form.value == (string)$option[$form['key']])}selected{/if}>{$option[$form['option']]|raw|clear_js}</option>
                {/volist}
            {/notempty}
        </select>
    </div>
    {/eq}

    <div class="col-xs-12">
        {notempty name="form.tips"}
        <div class="help-block">{$form.tips|raw|clear_js}</div>
        {/notempty}
    </div>
</div>